package com.markerhub.mapper;

import com.markerhub.common.vo.ClassVO;
import com.markerhub.common.vo.ClassmateVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StudentClassMapper {

    @Select("SELECT DISTINCT mc.id, mc.name, mu.real_name as teacherName, " +
            "mg.group_name as groupName " +
            "FROM m_manager_class mc " +
            "JOIN m_teaching_student_in_class tsic ON mc.id = tsic.class_id " +
            "JOIN m_user mu ON mc.teacher_id = mu.id " +
            "JOIN m_manager_student ms ON tsic.student_id = ms.id " +
            "LEFT JOIN m_manager_group mg ON tsic.group_id = mg.id " +
            "WHERE ms.login_id = #{studentId}")
    List<ClassVO> selectStudentClasses(@Param("studentId") Long studentId);

    @Select("SELECT DISTINCT ms.stu_name, ms.current_grade, " +
            "mg.group_name as groupName " +
            "FROM m_manager_student ms " +
            "JOIN m_teaching_student_in_class tsic ON ms.id = tsic.student_id " +
            "LEFT JOIN m_manager_group mg ON tsic.group_id = mg.id " +
            "WHERE tsic.class_id = #{classId}")
    List<ClassmateVO> selectClassmates(@Param("classId") Integer classId);

    @Select("SELECT COUNT(*) FROM m_teaching_student_in_class tsic " +
            "JOIN m_manager_student ms ON tsic.student_id = ms.id " +
            "WHERE ms.login_id = #{studentId} AND tsic.class_id = #{classId}")
    int countStudentInClass(@Param("studentId") Long studentId, @Param("classId") Integer classId);
}